﻿using BCCommon;
using BCEntity.Common.Payment.Payment;
using Dapper;
using System.Collections.Generic;
using System.Data;

namespace BCData.Common.Payment.Payment
{
    public class PaymentChannelData : IPaymentChannelData
    {
        private const string SQL_SELECT_ITEMS = @"SELECT PaymentChannelId, Name, Description, Tips, Logo, `Order`, Enabled, ServiceImpl, AppliedTo, CreateTime,AppliedUserId
                                                  FROM PaymentChannel";
        private const string SQL_SELECT_ITEM_BY_PAYMENTCHANNELID = @"SELECT PaymentChannelId, Name, Description, Tips, Logo, `Order`, Enabled, ServiceImpl, AppliedTo, CreateTime,AppliedUserId
                                                                     FROM PaymentChannel
                                                                     WHERE PaymentChannelId = ?PaymentChannelId";

        protected readonly IDatabaseContext databaseContext;

        public PaymentChannelData(IDatabaseContext databaseContext)
        {
            this.databaseContext=databaseContext;
        }

        public IEnumerable<PaymentChannelEntity> GetPaymentChannels()
        {
            return this.databaseContext.Slave.Query<PaymentChannelEntity>(SQL_SELECT_ITEMS);
        }

        public PaymentChannelEntity GetPaymentChannel(string paymentChannelId)
        {
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("?PaymentChannelId", paymentChannelId, DbType.AnsiString);

            return this.databaseContext.Slave.QueryEntity<PaymentChannelEntity>(SQL_SELECT_ITEM_BY_PAYMENTCHANNELID, parameters);
        }
    }
}
